<?php if (!defined('THINK_PATH')) exit();?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo (L("home_title")); ?></title>
<link rel="stylesheet" type="text/css" href="../Public/css/style.css" />
<script type="text/javascript" src="__PUBLIC__/js/utils.js"></script>
<script type="text/javascript" src="../Public/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
<link rel="stylesheet" type="text/css" href="__PUBLIC__/js/tbox/box.css" />
<script type="text/javascript" src="__PUBLIC__/js/tbox/box.js"></script>
</head>
<body>
    <script type="text/javascript">
        var URL = "__URL__";
        var pubPath = '../Public/';
        var process_request='<?php echo (L("process_request")); ?>';
    </script>

<div class="so_main">
    <div class="page_tit">功能列表</div>
    <div class="Toolbar_inbox">
        <a href="__URL__/add" class="btn_a""><span>新增功能</span></a>
        <a href="javascript:void(0);" class="btn_a" onclick="del();"><span>删除功能</span></a>
    </div>
    <div class="list" id="listDiv">
        <table width="100%" cellspacing="0" cellpadding="0" id="list-table">
            <tr>
                <th>功能名称</th>
                <th>分组</th>
                <th>模块</th>
                <th>方法</th>
                <th>排序</th>
                <th width="80px" align="center" valign="middle">是否显示</th>
                <th width="80px" align="center" valign="middle">是否受控</th>
                <th>操作</th>
            </tr>
            <?php if(is_array($list)): $i = 0; $__LIST__ = $list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$cat): $mod = ($i % 2 );++$i;?><tr align="center" class="<?php echo ($cat["level"]); ?>" id="<?php echo ($cat["level"]); ?>_<?php echo ($cat["id"]); ?>" overstyle='on'>
                    <td align="left" class="first-cell nowrap" valign="top"  >
                        <img src="../Public/images/menu_minus.gif"  id="icon_<?php echo ($cat["level"]); ?>_<?php echo ($cat["id"]); ?>" width="9" height="9"  border="0" style="margin-left:<?php echo ($cat["level"]); ?>em;cursor:pointer;" onclick="rowClicked(this)" />
                    &nbsp;<span><a href="__URL__/edit/id/<?php echo ($cat["id"]); ?>"><?php echo ($cat["mc"]); ?></a></span>
                    </td>
                    <td><span onclick="ui.ltedit(this, 'group_name', <?php echo ($cat["id"]); ?>)"><?php echo (($cat["group_name"])?($cat["group_name"]):"&nbsp;"); ?></span></td>
                    <td><span onclick="ui.ltedit(this, 'module_name', <?php echo ($cat["id"]); ?>)"><?php echo (($cat["module_name"])?($cat["module_name"]):"&nbsp;"); ?></span></td>
                    <td><span onclick="ui.ltedit(this, 'action_name', <?php echo ($cat["id"]); ?>)"><?php echo (($cat["action_name"])?($cat["action_name"]):"&nbsp;"); ?></span></td>
                    <td><span onclick="ui.ltedit(this, 'sort_order', <?php echo ($cat["id"]); ?>)"><?php echo (($cat["sort_order"])?($cat["sort_order"]):"&nbsp;"); ?></span></td>
                    <td align="center" valign="middle"><img style="cursor:pointer;" src="../Public/images/<?php if(($cat['is_state']) == "1"): ?>yes<?php else: ?>no<?php endif; ?>.gif" onclick="tree_toggle(this, 'is_state', <?php echo ($cat["id"]); ?>)" /></eq></td>
                    <td align="center" valign="middle"><img style="cursor:pointer;" src="../Public/images/<?php if(($cat['is_control']) == "1"): ?>yes<?php else: ?>no<?php endif; ?>.gif" onclick="tree_toggle(this, 'is_control',<?php echo ($cat["id"]); ?>)" /></eq></td>
                    <td><a href="__URL__/edit/id/<?php echo ($cat["id"]); ?>">修改</a> | <a href="javascript:void(0);" class="btn_a" onclick="remove('<?php echo ($cat["id"]); ?>','<?php echo ($cat["level"]); ?>_<?php echo ($cat["id"]); ?>','<?php echo ($cat["mc"]); ?>');"><span>删除</span></a>
</td>
                </tr><?php endforeach; endif; else: echo "" ;endif; ?>
        </table>
    </div>

</div>

<script language="JavaScript">
<!--
function tree_toggle(obj,fields,ids){
    var vals = (obj.src.match(/yes.gif/i)) ? 0 : 1;
    $.getJSON(URL+"/_toggle",{id:ids,val:vals,field:fields},function(res){
        if (res.status==1){
            obj.src = (res.data >0) ? '../Public/images/yes.gif' : '../Public/images/no.gif';
        }else{
            ui.error(res.info);
        }
    });
}
function remove(ids,rowindex,name){
    if(confirm('您将删除功能['+name+']，删除后无法恢复，确定继续？')) {
        $.getJSON(URL+"/remove",{
            id:ids
        },function(res){
            if(res.status==1) {
                ui.success('删除成功'+name);
                $('#'+rowindex).remove();
            }else {
                ui.error('删除失败!'+res.info);
            }
        });
    }
}
var imgPlus = new Image();
imgPlus.src = pubPath + "images/menu_plus.gif";
/**
 * 折叠分类列表
 */
function rowClicked(obj)
{
   // 当前图像
  img = obj;
  // 取得上二级tr>td>img对象
  obj = obj.parentNode.parentNode;
  // 整个分类列表表格
  var tbl = document.getElementById("list-table");
  // 当前分类级别
  var lvl = parseInt(obj.className);
  // 是否找到元素
  var fnd = false;
  var sub_display = img.src.indexOf('menu_minus.gif') > 0 ? 'none' : (Browser.isIE) ? 'block' : 'table-row' ;
  // 遍历所有的分类
  for (i = 0; i < tbl.rows.length; i++)
  {
      var row = tbl.rows[i];
      if (row == obj)
      {
          // 找到当前行
          fnd = true;
          //document.getElementById('result').innerHTML += 'Find row at ' + i +"<br/>";
      }
      else
      {
          if (fnd == true)
          {
              var cur = parseInt(row.className);
              var icon = 'icon_' + row.id;
              if (cur > lvl)
              {
                  row.style.display = sub_display;
                  if (sub_display != 'none')
                  {
                      var iconimg = document.getElementById(icon);
                      iconimg.src = iconimg.src.replace('plus.gif', 'minus.gif');
                  }
              }
              else
              {
                  fnd = false;
                  break;
              }
          }
      }
  }

  for (i = 0; i < obj.cells[0].childNodes.length; i++)
  {
      var imgObj = obj.cells[0].childNodes[i];
      if (imgObj.tagName == "IMG" && imgObj.src != pubPath +'images/menu_arrow.gif')
      {
          imgObj.src = (imgObj.src == imgPlus.src) ? pubPath +'images/menu_minus.gif' : imgPlus.src;
      }
  }
}
//-->
</script>
<script>
    //鼠标移动表格效果
    $(document).ready(function(){
        $("tr[overstyle='on']").hover(
        function () {
            $(this).addClass("bg_hover");
        },
        function () {
            $(this).removeClass("bg_hover");
        }
    );
    });
</script>

    </body>
</html>